**
**  Political Economy of Consumer Debt Relief
**
**  Code for Creating the Maps of Figure B1
**
**  July 2024
**  

cd  "/Users/zas/Library/CloudStorage/Dropbox/Vote Buying_shared/Georgia/!REStat/Replication/FigureB1"

ssc install spmap 
ssc install shp2dta

* Import shape files from Georgia (GEO) Administrative Boundary Common Operational Database (COD-AB) at administrative levels 1 and 2.
* Provided by the United Nations Office for the Coordination of Humanitarian Affairs and made available by the National Statistics Office of Georgia.
* https://data.humdata.org/dataset/3ee95199-2dfe-40fc-b9bd-b44cc8c91024/resource/ac2b2747-18a2-43c9-abbb-4ab2c5c539a3/download/geo_adm_geostat_20191018_shp.zip.
 
* import administrative level 1: Tbilisi
shp2dta using "adm1/geo_admbnda_adm1_geostat_20191018.shp", database(geod_tb) coordinates(geocoord_tb) genid(id) replace
use geocoord_tb, clear
keep if _ID == 13
replace _ID =  99 if _ID == 13
save geocoordi_tbilisi_, replace

* import administrative level 2: Rest of country
shp2dta using "adm2/geo_admbnda_adm2_geostat_20191018.shp", database(geod) coordinates(geocoord) genid(id) replace
use geocoord, clear
append using geocoordi_tbilisi_
sort _ID
save geocoord, replace

use geod, clear

rename ADM2_EN District
replace District = "Zestafoni" if District == "Zestaponi"

merge 1:1 District using Salome, gen(_m1)
rename No district_no
merge m:1 district_no "/Users/zas/Library/CloudStorage/Dropbox/Vote Buying_shared/Georgia/!REStat/Replication/auxiliary_data/treatment_intensity_districts", gen(_m3)

* aggregate results for Tbilisi
replace id = 99 if District== "Mtatsminda"
replace District = "Tbilisi" if inlist(District,"Mtatsminda","Vake","Saburtalo","Krtsanisi","Isani")
replace District = "Tbilisi" if inlist(District,"Samgori","Chugureti","Didube","Nadzaladevi","Gldani")

bys District: egen f = total(SolomeI) if District == "Tbilisi"
bys District: egen g = total(SolomeII) if District == "Tbilisi"
bys District: egen i = mean(d_debt_tot_ln) if District == "Tbilisi" 

replace SolomeI  = f if id == 99
replace SolomeII = g if id == 99
replace d_debt_tot_ln = i if id == 99
gen gr = (SolomeII - SolomeI) / SolomeI

* vote change
spmap gr using geocoord, id(id) fcolor(Blues) title("Vote growth rate") ///
subtitle("for Salome Zurabishvili from first to second round")
graph export vote_growth.png, replace as(png)

*  treatment 
spmap d_debt_tot_ln using geocoord, id(id) fcolor(Blues) title("Treatment intensity")
graph export t_intensity.png, replace as(png)

rm "geocoord.dta"
rm "geocoord_tb.dta"
rm "geocoordi_tbilisi_.dta"
rm "geod.dta"
rm "geod_tb.dta"
